<?php
/**
 * 1018自定菜单
 *
 * 编写参照store_order.php
 *
 *
 * @网店运维提供技术支持 授权请购买shopnc授权
 * @license    http://www.shopwwi.com
 * @link       交流群号：111731672
 */



defined('ByShopWWI') or exit('Access Invalid!');
class menu_1018Control extends BaseSellerControl {
    public function __construct() {
        parent::__construct();
        Language::read('member_store_index');
    }

    /**
     * 订单列表
     *
     */
    public function indexOp() {
        $model_order = Model('order');

        if(isset($_GET['state_type'])){
            $_order_lis= $model_order->goods_state($_GET);
            $_order_list= $this->goods_link($_order_lis);
            Tpl::output('order_list',$_order_list);
            Tpl::output('show_page',$model_order->showpage());
            self::profile_menu('list',$_GET['state_type']);

            Tpl::showpage('menu_1018.index');
        }else{

        $_order_lis= $model_order->get_order();
        $_order_list= $this->goods_link($_order_lis);

        Tpl::output('order_list',$_order_list);
        Tpl::output('show_page',$model_order->showpage());
        self::profile_menu('list',$_GET['act']);

        Tpl::showpage('menu_1018.index');
        }
    }

    public function cancelOp(){

        $model_order = Model('order');

        $model_order->cancel_order($_GET['id']);   echo '1';
    }

    public function order_changeOp() {

        $id  = intval($_GET['id']);
        $model_order = Model('order');
        $order_info = $model_order->getOneOrder($id);

         $this->order_change($order_info);

    }


    private function order_change($order_info) {


        $goods_list=array('千足银'=>'1999.00','银大佛'=>'1500.00');
        $goods_state=array('0'=>'待发货','1'=>'已发货');

        Tpl::output('goods_list',$goods_list);
        Tpl::output('goods_state',$goods_state);
        Tpl::output('order_info',$order_info);
        Tpl::output('order_id',$order_info['order_id']);
        Tpl::showpage('order_modify','null_layout');

    }

    public function order_modifyOp(){

        $model_order = Model('order');
        $_POST['time']=time();
        $result=$model_order->order_modify($_POST);

        if (!$result) {
            showDialog('订单修改失败','','error',empty($_GET['inajax']) ?'':'CUR_DIALOG.close();',5);
        } else {
            showDialog('订单修改成功','reload','succ',empty($_GET['inajax']) ?'':'CUR_DIALOG.close();');
        }
    }

    public function add_orderOp(){
        $model_order = Model('order');
        self::profile_menu('list',$_GET['state_type']);

        if(isset($_POST['form_submit'])){
            $model_order = Model('order');
             $_POST['time']=time();    print_r($_POST);
             $result=$model_order->order_add($_POST);   print_r($result);
            if($result){
                header('Location:'.'index.php?act=menu_1018');
            }
        }else{

        }

        Tpl::showpage('menu_1018.add_order');
    }

    public function searchOp(){
        $model_order = Model('order');

        if(!empty($_POST['buyer']) | !empty($_POST['phone']) ){
            $condition=array();
            $search=array('buyer'=>'', 'phone'=>'');

            foreach ($_POST as $_key=>$_value){
                if(array_key_exists($_key, $search)){
                    if(!empty($_value)){
                        $condition[$_key]=$_value;
                    }
                }
            }

            $_order_lis=$model_order->order_search($condition);
            $_order_list= $this->goods_link($_order_lis);

        }else{
            $_order_lis= $model_order->get_order($_POST);
            $_order_list= $this->goods_link($_order_lis);
        }
        Tpl::output('order_list',$_order_list);
        Tpl::output('show_page',$model_order->showpage());
        self::profile_menu('list',$_GET['state_type']);
        Tpl::showpage('menu_1018.index');
    }

    //goods表关联
    private function goods_link($_order_list){
        $model_order = Model('order');
        foreach ($_order_list as $_key=> $_value){
            $goods_find=$model_order->find_good($_value['goods_name']);
            $_order_list[$_key]['goods_image']= $goods_find['goods_image'];
            $_order_list[$_key]['image_60_url']= UPLOAD_SITE_URL.'/'.ATTACH_GOODS.'/1/'.$goods_find['goods_image'];
        }

        return $_order_list;
    }


	    /**
     * 用户中心右边，小导航
     *
     * @param string    $menu_type  导航类型
     * @param string    $menu_key   当前导航的menu_key
     * @return
     */
    private function profile_menu($menu_type='',$menu_key='') {
        Language::read('member_layout');
        switch ($menu_type) {
            case 'list':
            $menu_array = array(
            array('menu_key'=>'menu_1018',          'menu_name'=>Language::get('nc_member_path_all_order'), 'menu_url'=>'index.php?act=menu_1018'),
            array('menu_key'=>'state_new',          'menu_name'=>'添加订单',  'menu_url'=>'index.php?act=menu_1018&op=add_order&state_type=state_new'),
            array('menu_key'=>'state_pay',          'menu_name'=>Language::get('nc_member_path_wait_send'), 'menu_url'=>'index.php?act=menu_1018&op=index&state_type=state_pay'),
            array('menu_key'=>'state_send',         'menu_name'=>Language::get('nc_member_path_sent'),      'menu_url'=>'index.php?act=menu_1018&op=index&state_type=state_send'),
//            array('menu_key'=>'state_success',      'menu_name'=>Language::get('nc_member_path_finished'),  'menu_url'=>'index.php?act=store_order&op=index&state_type=state_success'),
//            array('menu_key'=>'state_cancel',       'menu_name'=>Language::get('nc_member_path_canceled'),  'menu_url'=>'index.php?act=store_order&op=index&state_type=state_cancel'),
            );
            break;
        }
        Tpl::output('member_menu',$menu_array);
        Tpl::output('menu_key',$menu_key);
    }
}
